import React, { Component } from 'react';
/*
  学习目标：重定向和404页面
*/

import './index.css';

// 1.1 导入组件Redirect
import { BrowserRouter as Router, Route, Link, NavLink, Switch, Redirect } from 'react-router-dom';

export default class App extends Component {
  render() {
    return (
      <Router>
        <NavLink to="/home" activeClassName="xxx-xx-active" exact>
          点我跳到home
        </NavLink>
        <br />
        <NavLink to="/my" activeClassName="xxx-xx-active">
          点我跳到my
        </NavLink>
        <br />
        <Link to="/friend">点我跳到friend</Link>
        <Switch>
          {/* 1.2 设置重定向规则 form ='/'  to='/目标路径' */}
          {/* 💥一般重定向组件，要配合eacxt使用 */}
          <Redirect from="/" to="/home" exact></Redirect>
          <Route path="/home" component={Home}></Route>
          <Route path="/my" component={My}></Route>
          <Route path="/my" component={My}></Route>
          <Route path="/my" component={My}></Route>
          <Route path="/my" component={My}></Route>
          <Route path="/friend" component={Friend} exact></Route>
          {/* 2.1 不写path，一般用来设置404匹配规则 */}
          {/* 2.2👍 一般会把404规则，放在最后，相当于兜底效果 */}
          <Route component={NotFound}></Route>
        </Switch>
      </Router>
    );
  }
}

function NotFound(params) {
  return <h2>我是404页面</h2>;
}

function Home() {
  return <h1>我是Home组件</h1>;
}

function My() {
  return <h1>我是Find组件</h1>;
}
function Friend() {
  return <h1>我是Friend组件</h1>;
}
